﻿using CollegeReview.DataModels;
using CollegeReview.Web.IDataAdapters.Adapters;
using CollegeReview.Web.IDataAdapters.Interfaces;
using CollegeReview.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace CollegeReview.Web.Controllers
{
    //[Authorize]
    public class ValuesController : ApiController
    {
        ICollegeReviewAdapter _adapter = new CollegeReviewAdapter();
        // GET api/values
        public IHttpActionResult Get()
        {
            CollegeIndexVM vm = new CollegeIndexVM();
            vm.Colleges = _adapter.GetAllColleges();

            return Ok(vm);
        }

        // GET api/values/5
        public IHttpActionResult Get(int id)
        {
            CollegeDetailVM vm = new CollegeDetailVM();
            vm.College = _adapter.GetCollege(id);
            vm.Reviews = _adapter.GetAllReviews();
            return Ok(vm);
        }

        // POST api/values
        public IHttpActionResult Post([FromBody]College college)
        {
            return Ok(_adapter.AddCollege(college));
        }

        // PUT api/values/5
        //public void Put(int id, [FromBody]string value)
        public IHttpActionResult Put([FromBody]College college)
        {
            return Ok(_adapter.UpdateCollege(college));
        }

        // DELETE api/values/5
        public IHttpActionResult Delete(int id)
        {
            _adapter.DeleteCollege(id);
            return Ok();
        }
    }
}
